
"""
    pyprosim - a simple prolog compiler developed to PCS2056 course (Compilers) at Poli-USP\
    Copyright (C) 2008 Rodrigo Rodrigues da Silva

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
"""

import unittest
from pycoopiler.semantico import semantico
import logging
import time

class testsemantico(unittest.TestCase):
    
    def test_exp_chamada1(self):
        f = open('cases/test_semantico1_' + time.strftime("%H_%M_%S", time.localtime()), 'w')
        # expressao: (a+5)
        sem = semantico(f)
        sem.exp_push_ocb()
        sem.exp_push_id("a")
        sem.exp_verif_operand_push_add()
        sem.exp_push_num("5")
        sem.exp_verif_ocb()
        sem.code.write_file()
    
    def teste_exp_chamada2(self):
        f = open('cases/test_semantico2_' + time.strftime("%H_%M_%S", time.localtime()), 'w')
        # expressao: a*(b+3) - 5/d
        sem = semantico(f)
        sem.exp_push_id("a")
        sem.exp_verif_operand_push_mul()
        sem.exp_push_ocb()
        sem.exp_push_id("b")
        sem.exp_verif_operand_push_add()
        sem.exp_push_num("39")
        sem.exp_verif_ocb()
        sem.exp_verif_operand_push_sub()
        sem.exp_push_num("5")
        sem.exp_verif_operand_push_div()
        sem.exp_push_id("d")
        sem.exp_verif_emptystack()
        sem.exp_verif_emptystack()
        sem.code.write_file()
        
